<?php

     // Parsing Karakter-Karakter Khusus
function parseToXML($htmlStr)
{
     $xmlStr=str_replace('<','<',$htmlStr);
     $xmlStr=str_replace('>','>',$xmlStr);
     $xmlStr=str_replace('"','"',$xmlStr);

     return $xmlStr;
}

     // Menghubungkan Koneksi dengan server MySQL, ganti bagian $username, $password, dan $database.
$username="root";
$password="";
$database="database_jonu";

$connection=mysql_connect ('localhost', $username, $password);
if (!$connection) {
     die('Not connected : ' . mysql_error());
}

     // Memilih database MySQL yang aktif
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
     die ('Can\'t use db : ' . mysql_error());
}

     // Memilih semua baris pada tabel 'markers2'
$query = "SELECT * FROM jonu_post";
$result = mysql_query($query);
if (!$result) {
     die('Invalid query: ' . mysql_error());
}

     // Header File XML
header("Content-type: text/xml");

     // Parent node XML
echo '<markers>';

     // Iterasi baris, masing-masing menghasilkan node-node XML
while ($row = @mysql_fetch_assoc($result)){

     // Menambahkan ke node dokumen XML
     echo '<marker ';
     if(strlen($row['jonu_post_title']) > 50){
          echo 'name="' .substr($row['jonu_post_title'], 0, 50).'. . ." ';
     }else{
          echo 'name="' . parseToXML($row['jonu_post_title']) . '" ';
     }
     echo 'lat="' . $row['jonu_post_latitude'] . '" ';
     echo 'lng="' . $row['jonu_post_longitude'] . '" ';
     echo 'id="' . $row['jonu_post_id'].'" ';
     echo 'img="' . $row['jonu_post_image'].'" ';

     $post_id = $row['jonu_post_id'];
     $post_tgl = substr($row['jonu_post_date'], 8,2);
     $post_bln = substr($row['jonu_post_date'], 5,2);
     $permalink = $post_bln.'/'.$post_tgl.'/'.$post_id.'/'.$row['jonu_post_permalink'];                            
     
     echo 'link="' . $permalink.'" ';
     echo '/>';     
     

}

     // Akhir File XML (tag penutup node)
echo '</markers>';

?>